
/* GCSx
** TILESETBROWSE.H
**
** Tileset browsing
*/

/*****************************************************************************
** Copyright (C) 2003-2006 Janson
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** 
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
*****************************************************************************/

#ifndef __GCSx_TILESETBROWSE_H_
#define __GCSx_TILESETBROWSE_H_

class TileSetBrowseToolsMode : public Dialog {
private:
    class FrameWindow* myFrame;
    class TileSetBrowse* myBrowse;
    
    int font;
    int* modePtr;
    const int* hasMapsPtr;

public:
    enum {
        // Controls
        ID_MODE = 1,
    };

    TileSetBrowseToolsMode(class TileSetBrowse* tBrowseArea, int isFont, int* mode, const int* hasMaps);
    ~TileSetBrowseToolsMode();
    
    // Widgets adjust to mode change, disable/enable based on hasMaps
    void updateTools();

    // Creates a FrameWindow and returns, does not add self to desktop (use ->show() to do that)
    class FrameWindow* createWindowed();

    int event(int hasFocus, const SDL_Event* event);
    void childModified(Window* modified);
    int wantsToBeDeleted() const;
    WindowSort windowSort() const;
};

class TileSetBrowse : public Window {
private:
    class TileSetEdit* tileset;
    
    class TileSetBrowseToolsMode* toolsMode;
    
    int numTiles; // or number of collision maps, if in that mode
    int tileWidth;
    int tileHeight;
    int isFont;
    int hasMaps;
    int zoomWidth;
    int zoomHeight;
    int zoomRatio;
    int gridSize; // 0 or 1 only
    int showLetters;
    int tilesPerLine;
    int fixedTilesPerLine;
    int mode; // tiles, collision, or assign
    
    int cursor; // We keep this +selections at -1 to make our calculations easier
    int selectFirst; // Endpoints of selection, for dragging
    int selectLast;
    int selectBegin; // Actual first and last tiles selected, in a box pattern
    int selectEnd;   // only used when fixedTilesPerLine is enabled
    int haveFocus;
    int partialFocus;
    
    // Dirty range
    Rect dirtyRange;

    // Set partial dirties
    void setDirtyRange(int first, int last);
    void setDirtyBox(int begin, int end);

public:
    // Opens the window
    TileSetBrowse(TileSetEdit* myTileset) throw_File;
    ~TileSetBrowse();
    
    void reloadTileStats();
    int cursorState(int newPos = -1, int drag = 0);
    void realignSelection(); // Takes first/last and creates begin/end

    CommandSupport supportsCommand(int code) const;
    int event(int hasFocus, const SDL_Event* event);
    void resize(int newWidth, int newHeight, int newViewWidth = -1, int newViewHeight = -1, int fromParent = 0);
    void display(SDL_Surface* destSurface, Rect& toDisplay, const Rect& clipArea, int xOffset, int yOffset);
    WindowType windowType() const;
};

#endif

